package com.yanqu.road.server.cmd.vehiclesoul;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.vehicle.VehicleProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.vehicle.VehicleSoulModule;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;


@Cmd(code = Protocol.S_VSOUL_TURN, desc = "魂石转换")
public class VehicleTurnSoulCmd extends AbstractCommand {

	private int soulId;
	private int occ;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		VehicleProto.VehicleSoulTurnReqMsg reqMsg = VehicleProto.VehicleSoulTurnReqMsg.parseFrom(packet.getBytes());
		soulId = reqMsg.getSoulId();
		occ = reqMsg.getOcc();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ret = player.getModule(VehicleSoulModule.class).turnSoul(soulId,occ);
	}

	@Override
	public void sendData(GamePlayer player) {
		if(ret != 0){
			VehicleProto.VehicleSoulTurnRespMsg.Builder respMsg = VehicleProto.VehicleSoulTurnRespMsg.newBuilder();
			respMsg.setRet(ret);
			player.sendPacket(Protocol.U_VSOUL_TURN, respMsg);
		}
	}

}
